library fc_lbs;

import 'package:flutter/services.dart';
export 'src/models/flutter_baidu_location.dart';
export 'src/manager/fcl_bmf_location_manager.dart';
export 'src/interface/fcl_bmf_interface.dart';


const String kNativeChannelName = 'com.nd.fc_lbs.native';// com.nd.meeting.native com.nd.fc_lbs.native
const String kFlutterChannelName = 'com.nd.fc_lbs.flutter';

class LbsService {
  //flutter call native
  late final MethodChannel _nativeChannel = const MethodChannel(kNativeChannelName);

  //native call flutter
  final MethodChannel _flutterChannel = const MethodChannel(kFlutterChannelName);

  static final LbsService _instance = LbsService._internal();

  factory LbsService() {
    return _instance;
  }

  LbsService._internal() {
    _flutterChannel.setMethodCallHandler(nativeCallHander);
  }

  String _getMeetingPortalUrl() {
    return 'https://meeting.nd.com';
    // return AppCore().configs().service('fc_meeting')?['meeting_protal_url'];
  }

  String _getSdpAppId() {
    return 'sdp-app-id';
    // return AppCore().configs().app()['sdp']['sdp-app-id'];
  }

  //原生回调方法实现
  Future<dynamic> nativeCallHander(MethodCall methodCall) async {
    print('LbsService nativeCallHander method: ${methodCall.method}, arguments: ${methodCall.arguments}');
    try {
      switch (methodCall.method) {
        case 'onChannelEnd':
          var conferenceId = methodCall.arguments['conferenceId'] ?? '';
          var extId = methodCall.arguments['extId'] ?? '';
          var type = 'nd';
          // if (extId.isNotEmpty) {
          //   AppCore().api<MeetingChannelCallback>().onChannelEnd(conferenceId, extId, type);
          // }
          break;
        case 'newFlutterChannel':
          print('lbs---->newFlutterChannel: ${methodCall.arguments}');
          // if (extId.isNotEmpty) {
          //   AppCore().api<MeetingChannelCallback>().onChannelEnd(conferenceId, extId, type);
          // }
          break;
        default:
      }
    } catch (e) {
      print('LbsService nativeCallHander error: $e');
    }
  }

  /// 跳转地图共享页面
  Future mapShareHome() {
    return _nativeChannel.invokeMethod('mapShareHome', {'portalUrl': _getMeetingPortalUrl(), 'sdp-app-id': _getSdpAppId()});
  }

}
